<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of components</title>
  <meta name="keywords" content="components">
  <meta name="description" content="components(g) --- find the components of the graph g">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2003 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../../index.html">Home</a> &gt;  <a href="../index.html">matgraph</a> &gt; <a href="index.html">@graph</a> &gt; components.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../../index.html"><img alt="<" border="0" src="../../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="index.html">Index for matgraph/@graph&nbsp;<img alt=">" border="0" src="../../right.png"></a></td></tr></table>-->

<h1>components
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>components(g) --- find the components of the graph g</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>function p = components(g) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre class="comment"> components(g) --- find the components of the graph g
 If g has n vertices, this returns a partition of the [n] based on the
 components of g.</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="component.html" class="code" title="function vtcs = component(g,v)">component</a>	component(g,v) -- find vertices in v's component of g</li><li><a href="nv.html" class="code" title="function n = nv(g)">nv</a>	nv(g) --- number of vertices in g</li></ul>
This function is called by:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="bipartition.html" class="code" title="function p = bipartition(g)">bipartition</a>	part = bipartition(g) --- find bipartition of a bipartite graph</li><li><a href="euler_trail.html" class="code" title="function [elist, exists] = euler_trail(g)">euler_trail</a>	euler_trail(g) --- find an euler trail in g (if one exists)</li><li><a href="hamiltonian_cycle.html" class="code" title="function [hlist, exists] = hamiltonian_cycle(g,h)">hamiltonian_cycle</a>	hamiltonian_cycle(g) --- find a Hamiltonian cycle in g (if one exists)</li><li><a href="iso.html" class="code" title="function [yn,p] = iso(g,h,options)">iso</a>	[yn,p] = iso(g,h,options) --- is g isomorphic to h?</li></ul>
<!-- crossreference -->

<h2><a name="_subfunctions"></a>SUBFUNCTIONS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="#_sub1" class="code">function p = ind2part(ind)</a></li></ul>
<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function p = components(g)</a>
0002 <span class="comment">% components(g) --- find the components of the graph g</span>
0003 <span class="comment">% If g has n vertices, this returns a partition of the [n] based on the</span>
0004 <span class="comment">% components of g.</span>
0005 
0006 n = <a href="nv.html" class="code" title="function n = nv(g)">nv</a>(g);
0007 indicator = zeros(n,1);
0008 c = 0;
0009 
0010 <span class="keyword">while</span> (nnz(indicator)&lt;n)
0011     c = c+1;
0012     <span class="comment">% find first zero entry in indicator</span>
0013     i = find(indicator==0);
0014     i = i(1);
0015     
0016     <span class="comment">% get i's component</span>
0017     ci = <a href="component.html" class="code" title="function vtcs = component(g,v)">component</a>(g,i);
0018     
0019     indicator(ci) = c;
0020 <span class="keyword">end</span>
0021 <span class="comment">%p = indicator;</span>
0022 p = <a href="#_sub1" class="code" title="subfunction p = ind2part(ind)">ind2part</a>(indicator);
0023 
0024 
0025 
0026 <a name="_sub1" href="#_subfunctions" class="code">function p = ind2part(ind)</a>
0027 <span class="comment">% convert indicator vector to a partition</span>
0028 
0029 np = max(ind);
0030 A = cell(np,1);
0031 <span class="keyword">for</span> k=1:np
0032     A{k} = find(ind == k);
0033 <span class="keyword">end</span>
0034 p = partition(A);</pre></div>
<hr><address>Generated on Fri 30-Apr-2010 07:51:16 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> &copy; 2003</address>
</body>
</html>